<!--  费用预算-->
<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <search ref='search' :config='searchConfig' @search='search' @getHeight='getHeight' />

    <!-- table区域-begin -->
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        v-bind='vexConfig'
        :align='left'
        :border='true'
        :checkbox-config='checkboxConfig'
        :columns='columns'
        :data='dataSource'
        :height='pageHeight-seachHeight-94'
        :loading='loading'
        :resizable='true'
        :showOverflow='true'
        :toolbar-config='tableToolbar'
        size='mini'
        @checkbox-change='selectChangeEvent'
        @checkbox-all='selectChangeEvent'
      >
        <template #toolbar_buttons>
          <!-- 操作按钮区域 -->
          <div class='table-operator'>
            <a-button type='primary' @click='handleAdd'>新增</a-button>
            <a-button type='primary' @click='batchDel'>删除</a-button>
            <a-button type='primary' @click="stateChange(1)">启用</a-button>
            <a-button type='primary' @click="stateChange(0)">禁用</a-button>
            <a-button v-has="'costbudget:getOut'" type='primary'
                      @click="downExportXls('tpm_budget_fee_service')">导出
            </a-button>
          </div>
        </template>
        <template #aiRuleCode='{ row,rowIndex }'>
          <a v-has="'costbudget:change'" @click='handleDetail(row)'>{{ row.aiRuleCode }}</a>
        </template>
        <template #status='{ row }'>
          <a-switch :checked="row.status" size="small" @change="handleStatus(row,$event)"/>
        </template>
        <template #startDateAdd='{ row,rowIndex }'>
          <span>{{ row.startDate + '~' + row.endDate }}</span>
        </template>
        <template #action='{ row,rowIndex }'>
          <a v-has="'costbudget:change'" @click='handleEdit(row)'>编辑</a>
        </template>
        <template #pager>
          <vxe-pager
            :currentPage.sync='ipagination.current'
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :page-size.sync='ipagination.pageSize'
            :pageSizes='ipagination.pageSizeOptions'
            :total='ipagination.total'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <!-- table区域-end -->

    <aiAdd ref='modalForm' @ok='modalFormOk'></aiAdd>
  </a-card>
</template>

<script>
import { PageListMixin } from '@/mixins/PageListMixin'
import { getAction, postAction } from '@api/manage'
import aiAdd from '@views/tmr/budget/model/aiAdd'

import Vue from 'vue'
import JEllipsis from '@/components/cn-form/JEllipsis'
import { ACCESS_TOKEN } from '@/store/mutation-types'

let month = [
  {
    name: '01',
    value: '01'
  }, {
    name: '02',
    value: '02'
  }, {
    name: '03',
    value: '03'
  }, {
    name: '04',
    value: '04'
  }, {
    name: '05',
    value: '05'
  }, {
    name: '06',
    value: '06'
  }, {
    name: '07',
    value: '07'
  }, {
    name: '08',
    value: '08'
  }, {
    name: '09',
    value: '09'
  }, {
    name: '10',
    value: '10'
  }, {
    name: '11',
    value: '11'
  }, {
    name: '12',
    value: '12'
  }]

export default {
  name: 'AiRule',
  mixins: [PageListMixin],
  components: {
    JEllipsis,aiAdd
  },
  data() {
    return {
      permflag: 'tpm_budget_fee_impl',
      tokenHeader1: { 'loginUserToken': Vue.ls.get(ACCESS_TOKEN) },
      description: '费用预算',
      searchConfig: [
        {
          type: 'input',
          name: 'aiRuleCode',
          placeholder: '规则编码',
        }, {
          type: 'input',
          name: 'aiRuleName',
          placeholder: '规则名称'
        },
        {
          type: 'a-select',
          name: 'status',
          option: [{
            name: '启用',
            value: 1
          }, {
            name: '停用',
            value: 0
          }],
          placeholder: '状态'
        },
        {
          toggleSearchStatus:true,
          type:'date-range',
          name:'date',
          range:['startDate','endDate'],
          placeholder:['有效期开始时间','有效期结束时间']
        },
        ],
      columns: [
        { type: 'checkbox', width: 50, fixed: null ,field: 'a',},
        {
          title: 'ai规则编码',
          field: 'aiRuleCode',
          minWidth: 100,
          slots: { default: 'aiRuleCode' },
        },
        {
          title: 'ai规则名称',
          minWidth: 100,
          field: 'aiRuleName'
        },
        {
          title: '规则有效期',
          minWidth: 100,
          field: 'startDateAdd',
          slots: {default: 'startDateAdd'}
        },
        {
          title: '备注',
          minWidth: 80,
          field: 'remarks',
        },
        {
          title: '创建人',
          minWidth: 80,
          field: 'createName'

        },
        {
          title: '创建时间',
          minWidth: 120,
          field: 'createTime'
        },
        {
          title: '更新人',
          minWidth: 80,
          field: 'updateName'
        },
        {
          title: '更新时间',
          minWidth: 120,
          field: 'updateTime'
        },
        {
          title: '状态',
          field: 'status',
          minWidth: 80,
          fixed: 'right',
          slots: { default: 'status' },
        },
        {
          title: '操作',
          field: 'action',
          minWidth: 120,
          fixed: 'right',
          slots: { default: 'action' },
        }
      ],
      url: {
        // 列表接口
        list: window._CONFIG['domianTpmURL'] + '/tpmAiRule/findPageList',
        // 详情接口
        detail: window._CONFIG['domianTpmURL']+ "/tpmAiRule/getInfo",
        // 导出接口
        // exportXlsUrl: window._CONFIG['domianTpmURL']+"budget/tpmBudgetFee/exportXls",
        // 导入接口
        importExcelUrl: window._CONFIG['domianTpmURL'] + '/budget/tpmBudgetFee/importExcel',
        // 模版下载
        exportXlsUrl: window._CONFIG['domianTpmURL'] + '/budget/tpmBudgetFee/exportXls',
        // 删除接口
        deleteBatch: window._CONFIG['domianTpmURL'] + '/tpmAiRule/deleteBatch',
        // 启停用接口
        status: window._CONFIG['domianTpmURL'] + '/tpmAiRule/startOrStop',
        startOrStopUrl: window._CONFIG['domianTpmURL'] + '/tpmAiRule/startOrStop',
      }
    }
  },
  created() {


  },
  beforeMount() {


  },


  watch: {},
  computed: {
    // importExcelUrl: function(){
    //   return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    // }
  },
  methods: {
    importExcelUrl: function() {
      return `${this.url.importExcelUrl}`
    },

    onDblclicks: async function(record) {
      if (this.url.detail) {
        const res = await getAction(this.url.detail, { id: record.id })
        if (res && res.result) {
          record = res.result
        } else {
          this.$message.error(res.message)
        }
      }
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '查看'
      this.$refs.modalForm.disabled = true
    }

  }
}
</script>

<style lang='less' scoped>
@import '~@assets/less/common.less';

/deep/ .ant-pagination {
  float: right;
}

///deep/ .resize-table-th {
//  position: relative;
//}
///deep/ .table-draggable-handle {
//  height: 100% !important;
//  bottom: 0;
//  left: auto !important;
//  right: -5px;
//  cursor: col-resize;
//  touch-action: none;
//}

</style>